package com.heeexy.example.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.heeexy.example.service.BoardService;
import com.heeexy.example.util.CommonUtil;

@RestController
@RequestMapping("/board")
public class BoardController {
	@Autowired
    private BoardService boardService;
    /**
     * 查询文章列表
     */
  @RequiresPermissions("Board:list")
    @GetMapping("/list")
    public JSONObject list(HttpServletRequest request) {
       // return articleService.listArticle(CommonUtil.request2Json(request));
        return boardService.listBoard(CommonUtil.request2Json(request));
    }
  /**
   * 新增文章
   */

  @RequiresPermissions("Board:add")
  @PostMapping("/addBoard")
  public JSONObject addBoard(@RequestBody JSONObject requestJson) {
//      CommonUtil.hasAllRequired(requestJson, "content");
//      return articleService.addArticle(requestJson);
  	CommonUtil.hasAllRequired(requestJson, "ename,username,information");
      return boardService.addBoard(requestJson);
  }
  //删除商品
  @RequiresPermissions("board:delete")
  @PostMapping("/deleteBoard")
  public  JSONObject deleteEmp(@RequestBody JSONObject requestJson){
  	CommonUtil.hasAllRequired(requestJson, "ename");
      return  boardService.deleteBoard(requestJson);
  }

}
